﻿using System;
using System.ComponentModel.Composition;
using System.Diagnostics.CodeAnalysis;
using Boggle.Net.Model;
using Boggle.Net.Properties;
using Caliburn.Micro;

namespace Boggle.Net.ViewModels
{
    [Export(typeof(IShell))]
    public sealed class MainViewModel : Conductor<GameViewModel>, IShell
    {
        private readonly Random _randomSeries = new Random();

        public MainViewModel()
        {
            GenerateGame();
        }

        [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "Caliburn will dispose of ActiveItem" )]
        public void GenerateGame()
        {
            var seed = _randomSeries.Next();
            var tray = Tray.FilledWith(Game.SelectJumbledLetters(seed));

            ActiveItem = new GameViewModel(tray);
            DisplayName = String.Format("{0} #{1}", Resources.ApplicationName, seed);
        }
    }
}
